package com.xbs.dao.user;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.xbs.dao.conn.BaseDao;
import com.xbs.dao.conn.ParamSet;
import com.xbs.dao.conn.RowDatas;
import com.xbs.entity.UserEntity;

/**
 * 个人中心我的信息Dao类
 * 1.根据姓名查询出用户所有的信息
 * 2.根据原登录密码修改登录密码
 * 3.根据手机号修改支付密码
 * 4.根据原手机号修改手机号
 * @author Administrator
 *
 */
public class MessageDao extends BaseDao{
	
	//声明一个结果处理对象
	private RowDatas<UserEntity> user;
	
	/**
	 * 实例结果出来对象
	 */
	public MessageDao(){
		user = new getMessage();
	}
	
	/**
	 * 1.根据姓名查询出用户所有的信息
	 * @return
	 */
	public UserEntity selAll(String name){
		String sql = "select * from tb_user where user_name = ? ";
		return query(sql, new ParamSet(name), user);
	}
	
	/**
	 * 2.根据原登录密码修改登录密码
	 * @param name
	 * @return
	 */
	public int updatePwd(String password, String password1){
		String sql = "update tb_user set user_password = "+password+" where user_password = "+password1+"";
		return updateExecuted(sql);
	}
	
	/**
	 * 3.根据手机号修改支付密码
	 * @param password
	 * @return
	 */
	public int updatePay(String telphone, String paypassword){
		String sql = "update tb_user set user_paypassword = "+telphone+" where user_telphone = "+paypassword+" ";
		return updateExecuted(sql);
	}
	
	/**
	 * 4.根据原手机号修改手机号
	 * @return
	 */
	public int updateTel(String telphone, String telphone1){
		String sql = "update tb_user set user_telphone = "+telphone+" where user_telphone = "+telphone1+" ";
		return updateExecuted(sql);
	}
	
	private class getMessage implements RowDatas<UserEntity>{
		@Override
		public UserEntity getRowData(ResultSet rs) throws SQLException {
			UserEntity user = new UserEntity();
			user.setUser_name(rs.getString("user_name"));
			user.setUser_idcard(rs.getString("user_idcard"));
			user.setUser_telphone(rs.getString("user_telphone"));
			user.setUser_password(rs.getString("user_password"));
			user.setUser_paypassword(rs.getString("user_paypassword"));
			user.setUser_email(rs.getString("user_email"));
			return user;
		}
	}
}
